<template>
  <a-spin :spinning="confirmLoading">
    <j-form-container :disabled="formDisabled">
      <a-form-model ref="form" :model="model" :rules="validatorRules" slot="detail">
        <a-row>
          <a-col :span="24">
            <a-form-model-item label="店铺" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="shopId">
              <j-dict-select-tag type="list" v-model="model.shopId" dictCode="lg_shop_roster,ec_name,id" placeholder="请选择店铺" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="账期" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="billingCycle">
              <a-month-picker
                valueFormat="YYYY-MM"
                placeholder="请选择账期"
                v-model="model.billingCycle"
                style="width: 100%"
              />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="结算组织" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="orgId">
              <j-dict-select-tag type="list" v-model="model.orgId" dictCode="lg_base_settlement_org,name,id" placeholder="请选择结算组织" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="币种" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="currencyType">
              <j-dict-select-tag type="list" v-model="model.currencyType" dictCode="lg_k3cloud_currency,fname,fcode" placeholder="请选择币种" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="类型" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="type">
              <j-dict-select-tag type="list" v-model="model.type" dictCode="finance_amazon_order_summary_type" placeholder="请选择类型" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="产品金额" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productAmount">
              <a-input-number v-model="model.productAmount" placeholder="请输入产品金额" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="产品金额税费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="productAmountTax">
              <a-input-number v-model="model.productAmountTax" placeholder="请输入产品金额税费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="客户运费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customerFreight">
              <a-input-number v-model="model.customerFreight" placeholder="请输入客户运费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="客户运费税费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="customerFreightTax">
              <a-input-number v-model="model.customerFreightTax" placeholder="请输入客户运费税费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="买家支付的礼品包装费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="giftFee">
              <a-input-number v-model="model.giftFee" placeholder="请输入买家支付的礼品包装费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="买家支付的礼品包装费税费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="giftFeeTax">
              <a-input-number v-model="model.giftFeeTax" placeholder="请输入买家支付的礼品包装费税费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="亚马逊积分费用" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="amazonIntegralFee">
              <a-input-number v-model="model.amazonIntegralFee" placeholder="请输入亚马逊积分费用" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="折扣促销" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="discount">
              <a-input-number v-model="model.discount" placeholder="请输入折扣促销" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="折扣促销税费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="discountTax">
              <a-input-number v-model="model.discountTax" placeholder="请输入折扣促销税费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="亚马逊税费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="amazonTax">
              <a-input-number v-model="model.amazonTax" placeholder="请输入亚马逊税费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="平台手续费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="platformFee">
              <a-input-number v-model="model.platformFee" placeholder="请输入平台手续费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="FBA手续费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="fbaFee">
              <a-input-number v-model="model.fbaFee" placeholder="请输入FBA手续费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="月租" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="monthlyFee">
              <a-input-number v-model="model.monthlyFee" placeholder="请输入月租" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="广告费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="advertisingFee">
              <a-input-number v-model="model.advertisingFee" placeholder="请输入广告费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="提现" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="withdraw">
              <a-input-number v-model="model.withdraw" placeholder="请输入提现" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="其他交易费" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="otherFee">
              <a-input-number v-model="model.otherFee" placeholder="请输入其他交易费" style="width: 100%" />
            </a-form-model-item>
          </a-col>
          <a-col :span="24">
            <a-form-model-item label="其他" :labelCol="labelCol" :wrapperCol="wrapperCol" prop="other">
              <a-input-number v-model="model.other" placeholder="请输入其他" style="width: 100%" />
            </a-form-model-item>
          </a-col>
        </a-row>
      </a-form-model>
    </j-form-container>
  </a-spin>
</template>

<script>

  import { httpAction, getAction } from '@/api/manage'
  import { validateDuplicateValue } from '@/utils/util'

  export default {
    name: 'FinanceAmazonOrderSummaryForm',
    components: {
    },
    props: {
      //表单禁用
      disabled: {
        type: Boolean,
        default: false,
        required: false
      }
    },
    data () {
      return {
        model:{
         },
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },
        confirmLoading: false,
        validatorRules: {
           shopId: [
              { required: true, message: '请输入店铺!'},
           ],
           billingCycle: [
              { required: true, message: '请输入账期!'},
           ],
           orgId: [
              { required: true, message: '请输入结算组织!'},
           ],
           currencyType: [
              { required: true, message: '请输入币种!'},
           ],
           productAmount: [
              { required: true, message: '请输入费用类型!'},
           ],
        },
        url: {
          add: "/finance/financeAmazonOrderSummary/add",
          edit: "/finance/financeAmazonOrderSummary/edit",
          queryById: "/finance/financeAmazonOrderSummary/queryById"
        }
      }
    },
    computed: {
      formDisabled(){
        return this.disabled
      },
    },
    created () {
       //备份model原始值
      this.modelDefault = JSON.parse(JSON.stringify(this.model));
    },
    methods: {
      add () {
        this.edit(this.modelDefault);
      },
      edit (record) {
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      submitForm () {
        const that = this;
        // 触发表单验证
        this.$refs.form.validate(valid => {
          if (valid) {
            that.confirmLoading = true;
            let httpurl = '';
            let method = '';
            if(!this.model.id){
              httpurl+=this.url.add;
              method = 'post';
            }else{
              httpurl+=this.url.edit;
               method = 'put';
            }
            httpAction(httpurl,this.model,method).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              that.confirmLoading = false;
            })
          }
         
        })
      },
    }
  }
</script>